package com.example.shell.util;

import java.time.Duration;
import java.time.LocalTime;

public class LocalTimeDifference {
    public static void main(String[] args) {
        // 定义两个 LocalTime 对象
        LocalTime time1 = LocalTime.of(10, 30);  // 10:30
        LocalTime time2 = LocalTime.of(14, 45);  // 14:45

        // 计算两个 LocalTime 之间的差异
        Duration duration = Duration.between(time1, time2);

        // 输出时间差的小时数、分钟数和秒数
        long hours = duration.toHours();
        long minutes = duration.toMinutes() % 60;  // 获取剩余的分钟数
        long seconds = duration.getSeconds() % 60;  // 获取剩余的秒数

        System.out.println("时间差: " + hours + "小时 " + minutes + "分钟 " + seconds + "秒");
    }

    public static long differenceHours(LocalTime time1,LocalTime time2){
        // 计算两个 LocalTime 之间的差异
        if (time1 == null || time2 == null){
            return 0L;
        }
        Duration duration = Duration.between(time1, time2);
        return duration.toHours();
    }
}